package culosic.mdpocket.html;

import culosic.mdpocket.core.Out;

public class HtmlOut implements Out
{
	public static String css;
	
	private StringBuffer buffer = new StringBuffer();
	private int level = 0;
	private boolean levelDumping = true;
	private String text;
	
	public HtmlOut(String css) {
		HtmlOut.css = css;
	}

	public void clear()
	{
		buffer.delete(0, buffer.length());
		buffer.append(css);
	}

	public void recoverLevel()
	{
		levelDumping = true;
	}

	public void pauseLevel()
	{
		levelDumping = false;
	}

	public boolean isLeveling()
	{
		return levelDumping;
	}

	/**
	 * 正数 提高级别    负数 降级别
	 * @param d 级别
	 */
	public void dumpLevel(int d)
	{
		level += d;
	}

	public void setText(String text)
	{
		this.text = text;
	}

	@Override
	public String toString()
	{
		return buffer.toString();
	}



	@Override
	public void put()
	{
		if (levelDumping && buffer.length() - 1 >= 0 && buffer.charAt(buffer.length() - 1) != '\n')
		{
			buffer.append('\n');
		}
		if (levelDumping && buffer.length() - 1 >= 0 && buffer.charAt(buffer.length() - 1) == '\n')
		{
			for (int i = 0; i < level; i ++)
			{
				buffer.append(' ');
			}
		}
		buffer.append(text);
	}

	@Override
	public void show()
	{
		System.out.println(buffer);
	}
	
}
